<?php

// +----------------------------------------------------------------------
// | POS机回调
// +----------------------------------------------------------------------
// | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
// +----------------------------------------------------------------------
// | Author: 微尘 <yicmf@qq.com>
// +----------------------------------------------------------------------

namespace app\controller\api\notify;

use app\common\controller\Base;
use app\event\ucenter\MemberInfo;
use app\event\ucenter\User as UserEvent;
use app\model\app\AppTaskBb as AppTaskBbModel;
use app\model\pos\Pos as PosModel;
use app\model\pos\PosTrade as PosTradeModel;
use app\model\pos\Store as StoreModel;
use app\event\pos\PosTrade as PosTradeEvent;
use app\model\ucenter\MemberInfo as MemberInfoModel;
use app\model\ucenter\User as UserModel;
use app\model\ucenter\UserMoneyLog;
use app\model\app\GameOrder as GameOrderModel;
use app\model\ucenter\UserTask as UserTaskModel;
use think\Exception;
use think\facade\Db;
use think\facade\Log;
use yicmf\tools\HttpService;
use yicmf\tools\Rsa;
use app\model\app\AppTask as AppTaskModel;
use app\model\app\AppTaskOrder as AppTaskOrderModel;
use app\model\app\AppTaskPz as AppTaskPzModel;
use app\event\app\Tui as TuiEvent;

class Tui extends Base
{


    public function test()
    {
        $headers = ['xdt-apikey' => 'XC1LiskucSyGOgPT'];
//        $re = HttpService::request('https://dt-dev.bd.jishu666.com/wapi/process/list_app', [], 'GET', $headers);
////
//        foreach ($re['content']['data'] as $index => $datum) {
//            $insert['tui_id'] = $datum['id'];
//            $insert['name'] = $datum['name'];
//            $insert['image'] = $datum['image'];
//            $insert['tui_status'] = $datum['status'];
//            $insert['bb_zd'] = $datum['bb_zd'];
//            $insert['dt_type'] = $datum['dt_type'];
//            $insert['rw_notice'] = $datum['rw_notice'];
//            $insert['has_qr'] = $datum['has_qr'];
//            $insert['update_time'] = $datum['up_time'];
//            $insert['create_time'] = $datum['created'];
//            dump($insert);
//            if (!AppTaskModel::where('tui_id', $insert['tui_id'])->count()) {
//                AppTaskModel::create($insert);
//            }
//        }
//
//        dump($re['content']);
////        exit();
//        $re = HttpService::request('https://dt-dev.bd.jishu666.com/wapi/process/list_apprw', ['appid' => 797], 'GET', $headers);
//
//
//        $task = AppTaskModel::where('tui_id', 797)->find();
//        $task['jobs'] = $re['content']['data'];
//        $task->save();
//        $re = HttpService::request('https://dt-dev.bd.jishu666.com/wapi/process/app_bm_info', ['appid' => 797], 'GET', $headers);
//
//        $info = $re['content']['data'];
//        $task['bb_zds'] = $info['bb_zd'];
//        $task['select_bb_zd'] = $info['select_bb_zd'];
//        $task['bb_sm'] = $info['bb_sm'];
//        $task['pz_button_name'] = $info['pz_button_name'];
//        $task['tj_info_fileds'] = $info['tj_info_fileds'];
//        $task['team_bb_tip'] = $info['team_bb_tip'];
//        $task['ok_bb_tip'] = $info['ok_bb_tip'];
//        $task['bb_tj_tip'] = $info['bb_tj_tip'];
//        unset($info['bb_zd']);
//        unset($info['select_bb_zd']);
//        $task->save();
//
//        dump($info);
//        dump($task->toArray());
//        exit();
//        dump($info);
//        dump($task->toArray());

//        $param['file'] = '';
//
////        $param['file'] = '@'.public_path().'logo.png';
//        $param['lx'] = 'img2';
//        $re = HttpService::request('https://dt-dev.bd.jishu666.com/wapi/process/up_file',$param,'POST', $headers);
//        dump($re);
//        exit();

        $param['appid'] = 797;
        $param['wb_uid'] = 797112;
        $param['wb_bs'] = time();
        $param['data'] = [[
            'name' => '张三1',
            'mobile_number' => '13100001121',
            'qianyue_jietu' => 'https://rtboss.bd.cn/up/img2/144/20241126113704mWbMGMTTQV.png',
            'quark_renwu' => 'quark_renwuliang',
        ]];
        dump($param);
        // 宝贝
        $re = HttpService::request('https://dt-dev.bd.jishu666.com/wapi/process/save_bb', $param, 'POST', $headers);
        //报备 1740148 1740149
        dump($re);
//
//        ["code"] => int(1)
//    ["msg"] => string(21) "恭喜，报备成功"
//    ["data"] => array(1) {
//        ["id"] => int(1763474)
//    }
    }

    public function order()
    {

        $t = new TuiEvent();
        dump($t->getOrders());

        /**
         * "order_sn": "2024041013304156711436", //订单编号 确定唯一性用此字段判断
         * "status": "1", //订单状态 1成功 2失败
         * "ms": "测试数据1", //描述
         * "fail_reason": "", //失败原因/描述，成功订单一般是描述
         * "money": "60.00", //订单金额
         * "created_at": "1712727041", //创建时间时间戳
         * "rw_id": "350", //任务ID 对应项目-任务列表中的id
         * "rw_name": "移动端拉新", //任务名称（可能会变）
         * "appid": "90", //项目ID
         * "total_count": "10", //订单数量
         * "bb_id": "584015", //报备ID
         * "pz_id": "0", //凭证ID
         * "wb_uid": "18924", //外部UID
         * "wb_bs": "18924", //外部标识
         * "created": "2024-04-10 13:30:41" //创建时间
         */
    }

    public function info()
    {

        $headers = ['xdt-apikey' => 'k8PwKSwpQtpXDf4F'];


        $re = HttpService::request('https://dt.bd.cn/wapi/process/detail_app', ['appid' => 434], 'GET', $headers);
        dump($re['content']);
        $data = $re['content']['data'];

        $data['tui_id'] = $data['id'];
        $data['tui_status'] = $data['status'];
        $data['update_time'] = $data['up_time'];


        unset($data['id']);
        unset($data['up_time']);
        unset($data['status']);
        unset($data['created']);
        $task = AppTaskModel::where('tui_id', 434)->find();
        $task->save($data);
//        AppTaskModel::where('tui_id',797)->update($data);

    }

    public function bb()
    {

        $headers = ['xdt-apikey' => 'XC1LiskucSyGOgPT'];///wapi/process/list_bb?status=1&wb_bs=&appid=项目ID

        //状态 1、已通过 2、已拒绝 3、待审核

        $re = HttpService::request('https://dt-dev.bd.jishu666.com/wapi/process/list_bb', ['appid' => 797], 'GET', $headers);
        dump($re['content']);


        foreach ($re['content']['data'] as $index => $data) {


            $data['bb_id'] = $data['id'];
            $data['post_data'] = json_decode($data['post_data'], true);
            $data['check_time'] = time_format('10 minute');
            unset($data['id']);
            unset($data['up_time']);
            unset($data['created']);

            AppTaskBbModel::create($data);

        }
        exit();


        $re = HttpService::request('https://dt-dev.bd.jishu666.com/wapi/process/detail_bb', ['appid' => 797, 'wb_bs' => '1735638065'], 'GET', $headers);
        dump($re['content']);
//审核状态 1已通过 2不通过 3审核中
        exit();
        $data = $re['content']['data'];

        $data['tui_id'] = $data['id'];
        $data['tui_status'] = $data['status'];
        $data['update_time'] = $data['up_time'];


        unset($data['id']);
        unset($data['up_time']);
        unset($data['status']);
        unset($data['created']);
//        $task = AppTaskModel::where('tui_id', 797)->find();
//        $task->save($data);
//        AppTaskModel::where('tui_id',797)->update($data);

    }

    public function pz()
    {

        $headers = ['xdt-apikey' => 'XC1LiskucSyGOgPT'];///wapi/process/list_bb?status=1&wb_bs=&appid=项目ID

        //状态 1、已通过 2、已拒绝 3、待审核

        $param['appid'] = 434;
        $param['wb_uid'] = 797112;
        $param['wb_bs'] = '1735638065';
        $param['data'] = [
            [
                'bb_id' => 1763472,
                'data' => [['id' => 588, 'data' => '13033336666']]
            ]
        ];
        dump($param);
        $re = HttpService::request('https://dt-dev.bd.jishu666.com/wapi/process/save_pz', $param, 'POST', $headers);
        dump($re['content']);
//        array(4) {
//        ["code"] => int(1)
//        ["msg"] => string(21) "恭喜，提交成功"
//        ["data"] => array(1) {
//            ["id"] => int(745)
//  }
//  ["request_id"] => string(30) "XDT20250103144252677786ec8c8a9"
//}

    }
    public function pzs()
    {

        $headers = ['xdt-apikey' => 'XC1LiskucSyGOgPT'];///wapi/process/list_bb?status=1&wb_bs=&appid=项目ID

        //状态 1、已通过 2、已拒绝 3、待审核

        $param['appid'] = 434;
//        $param['wb_uid'] = 797112;
//        $param['wb_bs'] = '1735638065';

        dump($param);
        $re = HttpService::request('https://dt-dev.bd.jishu666.com/wapi/process/list_pz', $param, 'GET', $headers);
        dump($re['content']);

        foreach ($re['content']['data'] as $index => $data) {
            $data['pz_id'] = $data['id'];
            $data['check_time'] = time_format('10 minute');
            unset($data['id']);
            unset($data['created']);

            AppTaskPzModel::create($data);
        }
//        array(4) {
//        ["code"] => int(1)
//        ["msg"] => string(21) "恭喜，提交成功"
//        ["data"] => array(1) {
//            ["id"] => int(745)
//  }
//  ["request_id"] => string(30) "XDT20250103144252677786ec8c8a9"
//}

    }
}
